package spring.module.zipfilter;

import java.util.ArrayList;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * 配置
 * 
 * @author Lucky Yang
 */
@Slf4j
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket docket() {
        // 打印访问地址
        log.info("API Document Address: {}", "/swagger-ui/index.html");
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                // 是否开启swagger
                .enable(true)
                .select()
                // 过滤条件，扫描指定路径下的文件
                //.apis(RequestHandlerSelectors.basePackage("spring.module.zipfilter"))
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                .paths(PathSelectors.any()) // 请求路径匹配，匹配所有
                .build().groupName("数据压缩");
    }

    private ApiInfo apiInfo() {
        /* 作者信息 */
        Contact contact = new Contact("Lucky Yang", "", "1290308475@qq.com");
        return new ApiInfo(
                "数据压缩",
                "为SpringBoot接口适配Gzip压缩数据请求加快超大Json对象的传输速度",
                "",
                "",
                contact,
                "MIT",
                "https://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>());
    }
}
